//
//  NIMInputToolBar+ZLCustom.m
//  ZLYoYoIM_Example
//
//  Created by 赵磊 on 2021/1/21.
//  Copyright © 2021 itzhaolei. All rights reserved.
//

#import "NIMInputToolBar+ZLCustom.h"
#import "UIImage+ZLIMCustom.h"
#import <NIMKit/UIView+NIM.h>
#import <NIMKit/UIImage+NIMKit.h>
#import <NIMKit/NIMInputBarItemType.h>
#import <NIMKit/UIImage+NIMKit.h>

@implementation NIMInputToolBar (ZLCustom)

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self setBackgroundColor:[UIColor whiteColor]];
        //
        UIButton *voiceButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [voiceButton setImage:[UIImage imageNamedInIM:@"ToolViewInputVoice"] forState:UIControlStateNormal];
        [voiceButton setImage:[UIImage imageNamedInIM:@"ToolViewInputVoiceHL"] forState:UIControlStateHighlighted];
        [voiceButton sizeToFit];
        self.voiceButton = voiceButton;
        
        
        UIButton *emoticonBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [emoticonBtn setImage:[UIImage imageNamedInIM:@"ToolViewEmotion"] forState:UIControlStateNormal];
        [emoticonBtn setImage:[UIImage imageNamedInIM:@"ToolViewEmotionHL"] forState:UIControlStateHighlighted];
        [emoticonBtn sizeToFit];
        self.emoticonBtn = emoticonBtn;
        
        UIButton *moreMediaBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [moreMediaBtn setImage:[UIImage imageNamedInIM:@"TypeSelectorBtn_Black"] forState:UIControlStateNormal];
        [moreMediaBtn setImage:[UIImage imageNamedInIM:@"TypeSelectorBtnHL_Black"] forState:UIControlStateHighlighted];
        [moreMediaBtn sizeToFit];
        self.moreMediaBtn = moreMediaBtn;
        
        UIButton *recordButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [recordButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [recordButton.titleLabel setFont:[UIFont systemFontOfSize:14.f]];
        [recordButton setBackgroundImage:[[UIImage nim_imageInKit:@"icon_input_text_bg"] resizableImageWithCapInsets:UIEdgeInsetsMake(15,80,15,80) resizingMode:UIImageResizingModeStretch] forState:UIControlStateNormal];
        recordButton.exclusiveTouch = YES;
        [recordButton sizeToFit];
        self.recordButton = recordButton;
        
        UIImageView *inputTextBkgImage = [[UIImageView alloc] initWithFrame:CGRectZero];
        [inputTextBkgImage setImage:[[UIImage nim_imageInKit:@"icon_input_text_bg"] resizableImageWithCapInsets:UIEdgeInsetsMake(15,80,15,80) resizingMode:UIImageResizingModeStretch]];
        self.inputTextBkgImage = inputTextBkgImage;
        
        NIMGrowingTextView *inputTextView = [[NIMGrowingTextView alloc] initWithFrame:CGRectZero];
        inputTextView.font = [UIFont systemFontOfSize:14.0f];
        inputTextView.maxNumberOfLines = self.maxNumberOfInputLines?:4;
        inputTextView.minNumberOfLines = 1;
        inputTextView.textColor = [UIColor blackColor];
        inputTextView.backgroundColor = [UIColor clearColor];
        inputTextView.nim_size = [inputTextView intrinsicContentSize];
        inputTextView.textViewDelegate = self;
        inputTextView.returnKeyType = UIReturnKeySend;
        self.inputTextView = inputTextView;
        
        //顶部分割线
        UIView *sep = [[UIView alloc] initWithFrame:CGRectZero];
        sep.backgroundColor = [UIColor lightGrayColor];
        sep.nim_size = CGSizeMake(self.nim_width, .5f);
        sep.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        [self addSubview:sep];
        
        //底部分割线
        UIView *bottomSep = [[UIView alloc] initWithFrame:CGRectZero];
        bottomSep.backgroundColor = [UIColor lightGrayColor];
        [self addSubview:bottomSep];
        self.bottomSep = bottomSep;
        
        [self setValue:@[
            @(NIMInputBarItemTypeVoice),
            @(NIMInputBarItemTypeTextAndRecord),
            @(NIMInputBarItemTypeEmoticon),
            @(NIMInputBarItemTypeMore),
          ] forKey:@"types"];
    }
    return self;
}

- (void)updateVoiceBtnImages:(BOOL)selected
{
    [self.voiceButton setImage:selected?[UIImage imageNamedInIM:@"ToolViewInputVoice"]:[UIImage imageNamedInIM:@"ToolViewKeyboard"] forState:UIControlStateNormal];
    [self.voiceButton setImage:selected?[UIImage imageNamedInIM:@"ToolViewInputVoiceHL"]:[UIImage imageNamedInIM:@"ToolViewKeyboardHL"] forState:UIControlStateHighlighted];
}

- (void)updateEmotAndTextBtnImages:(BOOL)selected
{
    [self.emoticonBtn setImage:selected?[UIImage imageNamedInIM:@"ToolViewEmotion"]:[UIImage imageNamedInIM:@"ToolViewKeyboard"] forState:UIControlStateNormal];
    [self.emoticonBtn setImage:selected?[UIImage imageNamedInIM:@"ToolViewEmotionHL"]:[UIImage imageNamedInIM:@"ToolViewKeyboardHL"] forState:UIControlStateHighlighted];
}

@end
